﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace IRepository
{
    public interface IBaseRepository<TEntity> where TEntity : class
    {
        /// <summary>
        /// 根据主键ID查询数据
        /// </summary>
        /// <param name="Id">主键ID</param>
        /// <returns></returns>
        TEntity QueryById(object Id);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IEnumerable<TEntity> Query(bool isNoTracking = true);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IEnumerable<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression, bool isNoTracking = true);
        /// <summary>
        /// 查询数据(可用于查询关联数据)
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IQueryable<TEntity> Queryable(Expression<Func<TEntity, bool>> whereExpression, bool isNoTracking = true);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <param name="orderByExpression">排序表达式</param>
        /// <param name="isAsc">是否是升序</param>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IEnumerable<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression, Expression<Func<TEntity, object>> orderByExpression, bool isAsc = true, bool isNoTracking = true);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <param name="intTop">查询Top n 条数据</param>
        /// <param name="orderByExpression">排序表达式</param>
        /// <param name="isAsc">是否是升序</param>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IEnumerable<TEntity> Query(
            Expression<Func<TEntity, bool>> whereExpression,
            int intTop,
            Expression<Func<TEntity, object>> orderByExpression = null,
            bool isAsc = true, bool isNoTracking = true);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <param name="intPageIndex">页码</param>
        /// <param name="intPageSize">每页大小</param>
        /// <param name="orderByExpression">排序表达式</param>
        /// <param name="isAsc">是否是升序</param>
        /// <param name="isNoTracking">是否追踪数据</param>
        /// <returns></returns>
        IEnumerable<TEntity> Query(
            Expression<Func<TEntity, bool>> whereExpression,
            int intPageIndex,
            int intPageSize,
            Expression<Func<TEntity, object>> orderByExpression = null,
            bool isAsc = true, bool isNoTracking = true);
        /// <summary>
        ///  添加数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        /// <returns></returns>
        int Add(TEntity entity);
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns></returns>
        bool DeleteById(object id);
        /// <summary>
        ///  删除数据
        /// </summary>
        /// <param name="model">数据实体</param>
        /// <returns></returns>
        bool Delete(TEntity model);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="whereExpression">查询表达式</param>
        /// <returns></returns>
        bool Delete(Expression<Func<TEntity, bool>> whereExpression);
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">更新实体</param>
        /// <param name="updatePropertyList">更新实体的字段</param>
        /// <returns></returns>
        bool Update(TEntity entity, IEnumerable<string> updatePropertyList = null);

    }
}
